/**
 * 酒店服务数据交互统一入口
 */
'use strict';
import axios from 'axios';
export const car = {
  getOrderList (params) {
    return queryAjax('orderList.json', params)
  },
  getOrderDetails (params) {
    return queryAjax('city/getCityId.json', params, 'get')
  },
  getCityId (params) {
    return queryAjax('city/getCityId.json', params, 'get')
  },
  getInputTips (params) {
    return queryAjax('/gaode/inputTips.json', params, 'get')
  },
  getEstimatePrice (params) {
    return queryAjax('estimatePrice.json', params)
  },
  createOrder (params) {
    return queryAjax('createOrder.json', params)
  },
  getCityList (params) {
    return queryAjax('city/getCityList.json', params, 'get')
  },
  preCompany (params) {
    return queryAjax('preCompany.json', params)
  },
  cancelOrder (params) {
    return queryAjax('cancelOrder.json', params)
  },
  needFine (params) {
    return queryAjax('needFine.json', params)
  },
  receiveOrder (params) {
    return queryAjax('receive.json', params)
  },
  getDistance (params) {
    return queryAjax('/gaode/getDistance.json', params)
  },
  getUnderWayTrip (params) {
    return queryAjax('getUnderWayTrip.json', params)
  }
};

function queryAjax (url, params, methods = 'post') {
  let $url = url.slice(0, 1) === '/' ? url : '/car/' + url;
  return axios[methods]($url, methods === 'get' ? {params: params} : params).catch(() => {
    alert('服务器错误')
  })
}
